/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package forge

import (
	"github.com/rs/zerolog/log"
	"github.com/spf13/cobra"
	"satellite/app/forge"
	"time"
)

// connectCmd represents the connectCmd command
var connectCmd = &cobra.Command{
	Use:     "connect",
	Aliases: []string{"conn", `/c`},
	Short:   "连接数据库",
	Long:    ``,
	Args:    Args,
	Run: func(cmd *cobra.Command, args []string) {
		runner := forge.NewConnect(connectOption).WithBase(base)
		err := runner.Run()
		if err != nil {
			log.Warn().Err(err).Send()
			return
		}
	},
}

var (
	connectOption = new(forge.ConnectOption)
)

func init() {
	forgeCmd.AddCommand(connectCmd)
	connectCmd.Flags().StringVarP(&connectOption.Host, "host", "H", "localhost", "数据库主机")
	connectCmd.Flags().IntVarP(&connectOption.Port, "port", "P", 3306, "数据库端口")
	connectCmd.Flags().StringVarP(&connectOption.User, "user", "u", "root", "数据库用户")
	connectCmd.Flags().StringVarP(&connectOption.Password, "password", "p", "", "数据库密码")
	connectCmd.Flags().IntVarP(&connectOption.Num, "num", "N", 1, "连接数量")
	connectCmd.Flags().DurationVarP(&connectOption.Duration, "duration", "d", 10*time.Second, "连接持续时间")
	connectCmd.Flags().BoolVarP(&connectOption.IsActivate, "activate", "a", false, "启用活跃连接")
}
